<template>
	<view class="page max">
		<hx-navbar title="完善个人信息" :fixed="true" bar-placeholder="hidden" transparent="auto"
			:background-color="[127, 74, 255, 1]" color="#ffffff" :pageScroll.sync="scrollData" />
		<image class="page_bg" :src="imgPrefix('/static/image/teacher/write_info_bg.png')"></image>
		<view class="tab_list">
			<view :class="['tab_item', navIndex == 1 ? 'tab_item_active' : '']">
				<view :class="['num', navIndex == 1 ? 'active' : '', navIndex >= 1 ? 'b-f' : '']"><text>1</text>
				<view :class="['line_height',navIndex == 2 ? 'line_height_left' : '']"></view></view>
				<text :class="['text', navIndex >= 1 ? 'active' : '']">填写个人信息</text>
			</view>
			<view :class="['tab_item', navIndex == 2 ? 'tab_item_active' : '']">
				<view :class="['num', navIndex == 2 ? 'active' : '', navIndex >= 2 ? 'b-f' : '']">
				<text>2</text>
				<view :class="['line_height',navIndex == 3 ? 'line_height_left' : '']"></view>
				</view>
				<text :class="['text', navIndex >= 2 ? 'active' : '']">实名认证</text>
			</view>
			<view :class="['tab_item', navIndex == 3 ? 'tab_item_active' : '']">
				<view :class="['num', navIndex == 3 ? 'active' : '', navIndex >= 3 ? 'b-f' : '']">
				<text>3</text>
				<view :class="['line_height',navIndex == 4 ? 'line_height_left' : '']"></view>
				</view>
				<text :class="['text', navIndex >= 3 ? 'active' : '']">教师资格证</text>
			</view>
			<view :class="['tab_item', navIndex == 4 ? 'tab_item_active' : '']">
				<view :class="['num', navIndex == 4 ? 'active' : '', navIndex >= 4 ? 'b-f' : '']"><text>4</text></view>
				<text :class="['text', navIndex >= 4 ? 'active' : '']">教师协议</text>
			</view>
		</view>
		<scroll-view class="main" scroll-y="true">
			<view>
				<block v-if="navIndex == 1">
					<view class="comment_box">
						<text>填写姓名</text>
						<input class="input" placeholder-class="placeholder" type="text" placeholder="请输入您的真实姓名" v-model="userInfo.name" />
					</view>
					<view class="comment_box">
						<text>手机号码</text>
						<view class="input">{{userInfo.phone}}</view>
						<!-- <input class="input" placeholder-class="placeholder" type="text" maxlength="11" placeholder="请输入11位手机号码" v-model="userInfo.phone" /> -->
					</view>
					<view class="comment_box flex-dir-column">
						<text>上传头像</text>
						<view class="img_list first_view">
							<block v-if="userInfo.headerAvatar.length > 0">
								<view  @tap="bindImg('headerAvatar', index)" v-for="(item, index) in userInfo.headerAvatar" :key="index" class="img_view">
									<image mode="aspectFill" class="img" :src="item.url||item.src" @error="imgErr(index, 'headerAvatar')"></image>
									<image @tap.stop="bindDelImg('headerAvatar', index, '头像')" class="img_icon" :src="imgPrefix('/static/image/teacher/del_icon.png')"></image>
									<view @tap.stop="bindAgain('headerAvatar', index)" class="err" v-if="item.state != 2">
										<block v-if="item.state == 1">
											<image class="state_icon" :src="imgPrefix('/static/image/teacher/err_icon.png')"></image>
											<text class="f_24 c-f">上传失败</text>
										</block>
										<block v-else>
											<text class="weui-loading state_icon"></text>
											<text class="f_24 c-f">上传中</text>
										</block>
									</view>
								</view>
							</block>
							<view v-if="userInfo.headerAvatar.length == 0" class="add_view" @tap="bindUploadFile(1, 'headerAvatar')">
								<image :src="imgPrefix('/static/image/teacher/add_icon.png')"></image>
								<text class="onelist-hidden">添加图片</text>
							</view>
						</view>
					</view>
					<view class="comment_box flex-dir-column">
						<text>个人图片<text class="f_24 gery1">{{ userInfo.userImgList.length }}/{{ pageCount }}</text></text>
						<view class="img_list first_view">
							<block v-if="userInfo.userImgList.length > 0">
								<view  @tap="bindImg('userImgList', index)" v-for="(item, index) in userInfo.userImgList" :key="index" :class="['img_view', item.state != 2 ? 'err' : '']"
								>
									<image mode="aspectFill" class="img" :src="item.url||item.src" @error="imgErr(index, 'userImgList')"></image>
									<image @tap.stop="bindDelImg('userImgList', index, '个人图片')" class="img_icon" :src="imgPrefix('/static/image/teacher/del_icon.png')"></image>
									<view @tap.stop="bindAgain('userImgList', index)" class="err" v-if="item.state != 2">
										<block v-if="item.state == 1">
											<image class="state_icon" :src="imgPrefix('/static/image/teacher/err_icon.png')"></image>
											<text class="f_24 c-f">上传失败</text>
										</block>
										<block v-else>
											<text class="weui-loading state_icon"></text>
											<text class="f_24 c-f">上传中</text>
										</block>
									</view>
								</view>
							</block>
							<view v-if="pageCount > userInfo.userImgList.length" class="add_view" @tap="bindUploadFile(numberOfPicturesLeft, 'userImgList')">
								<image :src="imgPrefix('/static/image/teacher/add_icon.png')"></image>
								<text class="onelist-hidden">添加图片</text>
							</view>
							<view class="add_view no_border" v-for="index of (3-userInfo.userImgList.length%4)" :key="index"></view>
							
							<view class="tips">
								*建议上传图片比例为1:1
							</view>
						</view>
					</view>
				</block>
				<block v-else-if="navIndex == 2">
					<view class="comment_box flex-dir-column no-b-b">
						<view class="dis-flex flex-x-between flex-y-center">
							<text>上传身份证照</text>
							<text @tap="bindSkip" class="f_26 gery1">跳过</text>
						</view>
						<view class="center_view">
							<view class="img_list">
								<block v-if="userInfo.cardTop.length > 0">
									<view
										@tap="bindImg('cardTop', index)"
										v-for="(item, index) in userInfo.cardTop"
										:key="index"
										:class="['img_view', item.state != 2 ? 'err' : '']"
									>
										<image mode="aspectFill" class="img" :src="item.src||item.url" @error="imgErr(index, 'cardTop')"></image>
										<image mode="aspectFill" @tap.stop="bindDelImg('cardTop', index, '身份证正面')" class="img_icon" :src="imgPrefix('/static/image/teacher/del_icon.png')"></image>
										<view @tap.stop="bindAgain('cardTop', index)" class="err" v-if="item.state != 2">
											<block v-if="item.state == 1">
												<image class="state_icon" :src="imgPrefix('/static/image/teacher/err_icon.png')"></image>
												<text class="f_24 c-f">上传失败</text>
											</block>
											<block v-else>
												<text class="weui-loading state_icon"></text>
												<text class="f_24 c-f">上传中</text>
											</block>
										</view>
									</view>
								</block>
								<view v-if="userInfo.cardTop.length == 0" class="add_view" @tap="bindUploadFile(1, 'cardTop')">
									<image :src="imgPrefix('/static/image/teacher/add_icon.png')"></image>
									<text class="onelist-hidden">上传身份证正面</text>
								</view>
							</view>
							<view class="img_list">
								<block v-if="userInfo.cardBottom.length > 0">
									<view @tap="bindImg('cardBottom', index)" v-for="(item, index) in userInfo.cardBottom" :key="index" :class="['img_view', item.state != 2 ? 'err' : '']">
										<image mode="aspectFill" class="img" :src="item.src||item.url" @error="imgErr(index, 'cardBottom')"></image>
										<image
											@tap.stop="bindDelImg('cardBottom', index, '身份证反面')"
											class="img_icon"
											:src="imgPrefix('/static/image/teacher/del_icon.png')"
										></image>
										<view @tap.stop="bindAgain('cardBottom', index)" class="err" v-if="item.state != 2">
											<block v-if="item.state == 1">
												<image class="state_icon" :src="imgPrefix('/static/image/teacher/err_icon.png')"></image>
												<text class="f_24 c-f">上传失败</text>
											</block>
											<block v-else>
												<text class="weui-loading state_icon"></text>
												<text class="f_24 c-f">上传中</text>
											</block>
										</view>
									</view>
								</block>
								<view v-if="userInfo.cardBottom.length == 0" class="add_view" @tap="bindUploadFile(1, 'cardBottom')">
									<image :src="imgPrefix('/static/image/teacher/add_icon.png')"></image>
									<text class="onelist-hidden">上传身份证反面</text>
								</view>
							</view>
							<view class="img_list">
								<block v-if="userInfo.cardHand.length > 0">
									<view  @tap="bindImg('cardHand', index)" v-for="(item, index) in userInfo.cardHand" :key="index" :class="['img_view', item.state != 2 ? 'err' : '']"
									>
										<image mode="aspectFill" class="img" :src="item.src||item.url" @error="imgErr(index, 'cardHand')"></image>
										<image @tap.stop="bindDelImg('cardHand', index, '手持身份证')" class="img_icon" :src="imgPrefix('/static/image/teacher/del_icon.png')"></image>
										<view @tap.stop="bindAgain('cardHand', index)" class="err" v-if="item.state != 2">
											<block v-if="item.state == 1">
												<image class="state_icon" :src="imgPrefix('/static/image/teacher/err_icon.png')"></image>
												<text class="f_24 c-f">上传失败</text>
											</block>
											<block v-else>
												<text class="weui-loading state_icon"></text>
												<text class="f_24 c-f">上传中</text>
											</block>
										</view>
									</view>
								</block>
								<view v-if="userInfo.cardHand.length == 0" class="add_view" @tap="bindUploadFile(1, 'cardHand')">
									<image :src="imgPrefix('/static/image/teacher/add_icon.png')"></image>
									<text class="onelist-hidden">上传手持身份证</text>
								</view>
							</view>
						</view>
						<view class="tips">
							*建议上传图片比例为1:1
						</view>
					</view>
						<view class="comment_box foramt flex-dir-column">
							<text class="foramt_text">上传标准</text>
							<image :src="imgPrefix('/static/image/teacher/foramt.png')" mode="aspectFill"></image>
						</view>
				</block>
				<block v-else-if="navIndex == 3">
					<view class="comment_box dis-flex flex-x-end flex-y-center">
						<text @tap="bindSkip" class="f_26 gery1 foramt">跳过</text>
					</view>
					<view class="comment_box">
						<text>证书编号</text>
						<input class="input" placeholder-class="placeholder" type="text" placeholder="请输入证书编号" v-model="userInfo.integerNumber" />
					</view>
					<view class="comment_box flex-dir-column">
						<view class="img_list last_view">
							<block v-if="userInfo.integerImg.length > 0">
								<view @tap="bindImg('integerImg', index)" v-for="(item, index) in userInfo.integerImg" :key="index" class="img_view">
									<image mode="aspectFill" class="img" :src="item.src||item.url" @error="imgErr(index, 'integerImg')"></image>
									<image @tap.stop="bindDelImg('integerImg', index, '教师资格证')" class="img_icon" :src="imgPrefix('/static/image/teacher/del_icon.png')"></image>
									<view @tap.stop="bindAgain('integerImg', index)" class="err" v-if="item.state != 2">
										<block v-if="item.state == 1">
											<image class="state_icon" :src="imgPrefix('/static/image/teacher/err_icon.png')"></image>
											<text class="f_24 c-f">上传失败</text>
										</block>
										<block v-else>
											<text class="weui-loading state_icon"></text>
											<text class="f_24 c-f">上传中</text>
										</block>
									</view>
								</view>
							</block>
							<view v-if="userInfo.integerImg.length == 0" class="add_view" @tap="bindUploadFile(1, 'integerImg')">
								<image :src="imgPrefix('/static/image/teacher/add_icon.png')"></image>
								<text class="onelist-hidden">上传教师资格证</text>
								<text class="onelist-hidden">请确保证件照片完整、清晰、无反光</text>
							</view>
						</view>
					</view>
				</block>
				<view v-else-if="navIndex == 4" class="dom_tree">
					<jyf-parser :html="agreementHtml" :domain="domain" lazy-load ref="article" selectable show-with-animation use-anchor>
						加载中...
					</jyf-parser>
				</view>
			</view>
		</scroll-view>
		<view class="bottom_btn">
			<view @tap.stop="bindbtn('next')" v-if="navIndex == 1" :class="['big_btn', cheakBtn[0] == 0 ? 'active_btn' : 'gery_btn']">下一步</view>
			<block v-else>
				<view @tap.stop="bindbtn('prev')" class="border_btn">上一步</view>
				<view @tap.stop="bindbtn('next')" v-if="navIndex == 2||navIndex == 3" :class="[cheakBtn[navIndex-1] == 0 ? 'active_btn' : 'gery_btn']">下一步</view>
				<view v-else @tap.stop="bindfinish()" :class="[min == 0 ? 'active_btn' : 'gery_btn']">{{min==0?'同意提交认证':min+'s'}}</view>
			</block>
		</view>
	</view>
</template>

<script>
import { chooseImage, random_string,deepClone } from '@/static/uitls/common.js';
import { commonMixinFun } from '@/static/mixins/common.js';
import API from '@/static/api/index.js';
import REG from '@/static/uitls/reg.js';
import jyfParser from '@/components/jyf-parser/jyf-parser';
const app = getApp();
export default {
	mixins: [commonMixinFun],
	components: {
		jyfParser
	},
	data() {
		return {
			scrollData: {}, // 存当前滚动的top值
			pageCount: 9,
			navIndex: 1,
			// {src:'',state:0,url:''} //state 0上传中 1 上传失败 2 上传成功  src存本地图片  url存线上图片  src本地图片因存储容量不足丢失时使用url线上图片代替
			userInfo: {
				wxapp_openid: uni.getStorageSync('wxapp_openid'), // wxapp_openid
				name: '', // 信息
				phone: uni.getStorageSync('user_phone'), //手机号
				headerAvatar: [], //头像 // {src:'',state:0,url:''}
				userImgList: [], //个人图片列表
				cardTop: [], //身份证正面
				cardBottom: [], //身份证背面
				cardHand: [], //手持身份证
				integerNumber: '', //教师资格证编号
				integerImg: [] //教师资格证图片
			},
			teacherInfo:{} ,// 教师请求回来的数据（此处是作为备份，提交时要过滤的）
			sendType:0,//提交类型  0为新增 1为提交
			agreementState:'loading',
			agreementHtml:'',
			domain: app.globalData.BASE_URL, //主域名，设置后将对于图片地址将自动拼接主域名或协议名
			min:15
		};
	},
	watch:{
		navIndex(val,oldVal){
			if(this.min>0){//倒计时数大于0
				if(val!=4){
					this.min=15
				}else{
					this.setMin()
				}
			}
		},
		teacherInfo(val,oldVal){
			let {nickname,phone,headeravatar,images,front_identity,back_identity,hand_identity,certificate_code,certificate_image}=val;
			let tempObj = {
				name:nickname,
				phone:phone,
				headerAvatar:this.setObjForamt(headeravatar),
				userImgList:this.setObjForamt(images),
				cardTop:this.setObjForamt(front_identity),
				cardBottom:this.setObjForamt(back_identity),
				cardHand:this.setObjForamt(hand_identity),
				integerNumber:certificate_code,
				integerImg:this.setObjForamt(certificate_image)
			}
			this.userInfo = deepClone(tempObj);
		}
	},
	onLoad() {
		let pages = getCurrentPages();  // 获取当前页面栈
		let prevPage = pages[pages.length - 2]; // -2 就是你上一页的数据 你上上页的数据就是-3 了以此类推！
		app._log("prevPage.route",prevPage.route)
		if(prevPage.route=="pages/teacher/my_account/index"||prevPage.route=="pages/index/index"){
			this.sendType=1
			if(prevPage.route=="pages/teacher/my_account/index"){
				this.navIndex=2
			}
			API.getTeacherInfo().then(({code,data,msg}) => {
				if (code == 1) {
					// app._log(this.null2str(data.teacher))
					let {teacher}=data
					if(teacher.images.length>0){
						let arr = []
						teacher.images.forEach(e=>{
							arr.push(e.image)
						})
						teacher.images=arr.join(',')
					}
					this.teacherInfo = this.null2str(teacher)
				}else{
					this.showToast(msg||'获取教师信息失败，请稍后再试')
				}
			}).catch(err=>{
				this.showToast(err.msg||'获取教师信息失败，请稍后再试')
			});
		}
		this.getTAgreement();
	},
	computed: {
		numberOfPicturesLeft:function(){
			return this.pageCount - this.userInfo.userImgList.length
		},
		cheakBtn: function() {
			let { name, phone, headerAvatar, userImgList, cardTop, cardBottom, cardHand, integerNumber, integerImg } = this.userInfo;
			let arr = [0, 0, 0]; //三个数组分别存各个的状态
			if (name == '') {
				// 1 姓名为空
				arr[0] = '请输入您的真实姓名';
			} else if (phone == '') {
				//  2手机号为空
				arr[0] = '请输入11位手机号码';
			} else if (!REG.isPoneAvailable(phone)) {
				// 3手机号格式错误
				arr[0] = '请输入正确的手机号码';
			} else if (headerAvatar.length == 0) {
				// 4 头像没有上传
				arr[0] = '请上传头像';
			} else if (headerAvatar.filter(o => o.state == 0).length > 0) {
				//5 头像有在上传中的
				arr[0] = '头像正在上传，请稍后';
			} else if (headerAvatar.filter(o => o.state == 1).length > 0) {
				//6 头像有图片上传失败
				arr[0] = '头像上传失败，请检查';
			} else if (userImgList.length == 0) {
				//7 个人图片没有上传
				arr[0] = '请上传图片';
			} else if (userImgList.filter(o => o.state == 0).length > 0) {
				//8 个人图片有在上传中的
				arr[0] = `第${Number(userImgList.findIndex(o => o.state == 1)+1)}张图片正在上传，请稍后`;
			} else if (userImgList.filter(o => o.state == 1).length > 0) {
				//9 个人图片有图片上传失败
				arr[0] = `第${Number(userImgList.findIndex(o => o.state == 1)+1)}张图片上传失败，请检查`;
			}
			
			if (cardTop.length == 0) {
				arr[1] = '请上传身份证正面';
			} else if (cardTop.filter(o => o.state == 0).length > 0) {
				arr[1] = `身份证正面正在上传，请稍后`;
			} else if (cardTop.filter(o => o.state == 1).length > 0) {
				arr[1] = `身份证正面上传失败，请检查`;
			}else if (cardBottom.length == 0) {
				arr[1] = '请上传身份证反面';
			} else if (cardBottom.filter(o => o.state == 0).length > 0) {
				arr[1] = `身份证反面正在上传，请稍后`;
			} else if (cardBottom.filter(o => o.state == 1).length > 0) {
				arr[1] = `身份证反面上传失败，请检查`;
			}else if (cardHand.length == 0) {
				arr[1] = '请上传手持身份证';
			} else if (cardHand.filter(o => o.state == 0).length > 0) {
				arr[1] = `手持身份证正在上传，请稍后`;
			} else if (cardHand.filter(o => o.state == 1).length > 0) {
				arr[1] = `手持身份证上传失败，请检查`;
			}
			
			if(integerNumber==''){
				arr[2] = '请填写证书编号';
			}else if (integerImg.length == 0) {
				arr[2] = '请上传教师资格证';
			} else if (integerImg.filter(o => o.state == 0).length > 0) {
				arr[2] = `教师资格证正在上传，请稍后`;
			} else if (integerImg.filter(o => o.state == 1).length > 0) {
				arr[2] = `教师资格证上传失败，请检查`;
			}
			return arr;
		},
		
		sendEditData:function(){ //判断哪些数据是修改了的，需要提交的数据
			let obj= {};
			let {teacherInfo,userInfo}=this;
			let {name,headerAvatar,userImgList,cardTop,cardBottom,cardHand,integerNumber,integerImg}=userInfo;
			if(name!=teacherInfo.nickname){ // 用户名修改了
				app._log('用户名修改了',name)
				obj.nickname = name
			}
			if(this.isEdit(teacherInfo.headeravatar,headerAvatar)){//头像修改
				obj.headeravatar=this.returnImg(headerAvatar[0]);
			}
			if(this.isEdit(teacherInfo.images,userImgList)){ // 个人图片修改
				let tempArr = []
				userImgList.forEach(e=>{
					tempArr.push(this.returnImg(e))
				})
				obj.images=tempArr;
			}
			if(this.isEdit(teacherInfo.front_identity,cardTop)){
				obj.front_identity=this.returnImg(cardTop[0]);
			}
			if(this.isEdit(teacherInfo.back_identity,cardBottom)){
				obj.back_identity=this.returnImg(cardBottom[0]);
			}
			if(this.isEdit(teacherInfo.hand_identity,cardHand)){
				obj.hand_identity=this.returnImg(cardHand[0]);
			}
			if(this.isEdit(teacherInfo.certificate_image,integerImg)){
				obj.certificate_image=this.returnImg(integerImg[0]);
			}
			if(integerNumber!=teacherInfo.certificate_code){ // 资格证书修改
				obj.certificate_code = integerNumber
			}
			return obj;
		}
	},
	
	onPageScroll(e) {
		this.scrollData = e;
	},
	methods: {
		// 设置秒数倒计时
		setMin(){
			setTimeout(()=>{
				if(this.navIndex==4){
					if(this.min>0){
						this.min-=1;
						this.setMin();
					}else{
						this.min=0;
					}
				}
			},1000)
		},
		getTAgreement(){
			this.agreementState = 'request'
			API.getTAgreement().then(({code,data,msg})=>{
				console.log(code,data,msg)
				if(code==1){
					this.agreementState = 'success'
					this.agreementHtml = data.content
				}else{
					this.showToast(msg||'获取协议失败')
					this.agreementState = 'error'
				}
			}).catch(err=>{
				this.agreementState = 'error'
			})
		},
		null2str(data) {
		  for (let x in data) {
		    if (data[x] === null) { // 如果是null 把直接内容转为 ''
		      data[x] = '';
		    } else {
		      if (Array.isArray(data[x])) { // 是数组遍历数组 递归继续处理
		        data[x] = data[x].map(z => {
		          return this.null2str(z);
		        });
		      }
		      if(typeof(data[x]) === 'object'){ // 是json 递归继续处理
		        data[x] = this.null2str(data[x])
		      }
		    }
		  }
		  return data;
		},
		setObjForamt(img=''){ // 数据回显时格式设置
			let tempArr = [];
			if(Array.isArray(img)){ // 传输的是数组
				img.forEach(e=>{
					tempArr.push({state:2,url:e})
				})
			}else if(img.length>0){ //单文件
				img.split(',').forEach(e=>{
					tempArr.push({state:2,url:e})
				})
			}
			return tempArr
		},
		isEdit(oldval='',nowVal=[]){ // 判断数据是否修改过  原始数据  当前数据
			app._log(oldval,nowVal);
			let oldArr = Array.isArray(oldval)?oldval:oldval.length>0&&oldval!=undefined?oldval.split(','):[];
			if(oldArr.length!=nowVal.length){ // 前后数据长度不一致
				app._log('数据有变化')
				return true;
			}else{
				let tempArr =[];
				app._log('何方神圣',nowVal)
				nowVal.forEach(e=>{
					tempArr.push(e.hasOwnProperty('url')?e.url:e.src)
				})
				// app._log('原数据',oldArr,'当前数据',nowVal)
				return !this.f(oldArr, tempArr);
			}
		},
		f(a, b) { // 判断两个数组是否一致
			 let m = new Map()
			 a.forEach(o => m.set(o, (m.get(o)||0) + 1));
			 b.forEach(o => m.set(o, (m.get(o)||0) - 1));
			 for (var value of m.values()) {
			 if(value !== 0){ return false}
			 }
			 return true
		},
		bindSkip(){
			uni.showModal({
				content:'确认要跳过吗？',
				cancelText: '留在该页',
				confirmText: '确认跳过',
				success:res=>{
					if(res.confirm){
						this.navIndex+=1
					}
				}
			})
		},
		bindfinish(){
			let {min}=this;
			if(min!=0){
				this.showToast('请阅读协议并在倒计时结束后提交')
			}else{
				this.bindbtn('finish')
			}
		},
		bindbtn(type) {
			let { navIndex, cheakBtn } = this;
			switch (type) {
				case 'prev':
					this.navIndex -= 1;
					break;
				case 'next':
					if (cheakBtn[navIndex - 1] != 0) {
						this.showToast(cheakBtn[navIndex - 1]);
					}else if(cheakBtn[navIndex-1]==0){
						this.navIndex += 1;
					}else{
						this.showToast(cheakBtn[navIndex-1])
					}
					break;
				case 'finish':
					app._log('填写完成，上传')
					let {sendType}=this;
					let obj = {}
					if(sendType==0){//新增
						let {wxapp_openid,name,phone,headerAvatar,userImgList,cardTop,cardBottom,cardHand,integerNumber,integerImg}=this.userInfo;
						let images = []
						userImgList.forEach(e=>{
							images.push(this.returnImg(e))
						})
						obj = {
							wxapp_openid:wxapp_openid,
							nickname:name,
							phone:phone,
							headeravatar:this.returnImg(headerAvatar[0]),
							images:images,
							front_identity:this.returnImg(cardTop[0]),
							back_identity:this.returnImg(cardBottom[0]),
							hand_identity:this.returnImg(cardHand[0]),
							certificate_code:integerNumber,
							certificate_image:this.returnImg(integerImg[0]),
						}
					}
					let send = sendType==0?API.createTeacher(obj):API.editTeacher(this.sendEditData)
					
					send.then(res=>{
						app._log(res)
						if(res.code==1){
							if(sendType==0){
								app.globalData.LOGION = true;
								app.globalData.userIdentity=1
								uni.setStorageSync('app_token',res.data.teachertoken)
								this.pageTo('/pages/teacher/audit_status_page/index')
							}else{
							this.showToast('修改成功，正在返回上页')
							setTimeout(()=>{
								uni.navigateBack({delta:1})
							},1500)
							}
						}else{
							this.showToast(res.msg||'请稍后再试')
						}
					}).catch((err)=>{
						this.showToast(err.msg||'请稍后再试')
					})
					break;
			}
		},
		returnImg(obj={}){
			if(JSON.stringify(obj)=='{}') return '';
			return obj.hasOwnProperty('url')?obj.url:obj.src
		},
		checkPhone(phone) {
			return REG.isPoneAvailable(phone);
		},
		// 单击图片
		bindImg(node, index) {
			//点击已经上传的图片
			let list = this.userInfo[node]
			let arr = list.filter(o=>o.state==2);
			let previewImg = [];
			arr.forEach(e=>{
				previewImg.push(e.hasOwnProperty('url')?e.url:e.src)
			})
			app.previewImg(previewImg,index);
		},
		// 图片上传失败时被点击了点击
		bindAgain(node, index){
			let {src}=this.userInfo[node][index];
			if(src){
				let _this=this;
				_this.fileUpload(src,(src, state, url = '') => {
						app._log(src, state, url);
						_this.userInfo[node][index].state = state ? 2 : 1;
						if (url != '') {
							_this.userInfo[node][index].url = url;
						}
					},
					err => {
						app._log(err);
					}
				);
			}
		},
		bindDelImg(node, index, text = '') {
			// 删除已经上传的图片
			uni.showModal({
				title: '删除确认',
				content: `您真的要删除${text}吗？`,
				cancelText: '返回',
				confirmText: '确认删除',
				success: res => {
					if (res.confirm) {
						let arr = this.userInfo[node];
						arr.splice(index, 1); //删除指定位置的图片
						this.userInfo[node] = arr;
						this.showToast('删除成功');
					}
				}
			});
		},
		imgErr(index, node) {
			//图片丢失处理
			let list = this.userInfo[node];
			if (list[index].hasOwnProperty('url')) { // 图片上传成功
				this.userInfo[node][index].src = list[index].url;
				delete this.userInfo[node][index].url;
			}else{ // 其它情况直接删除
				list.splice(index,1)
				this.userInfo[node] = list;
			}
		},
		
		// 生成文件名称并返回
		returnFileName(file) {
			return `${random_string(18)}${file.substring(file.lastIndexOf('.'), file.length)}`;
		},
		
		// 页面点击图片上传
		bindUploadFile(count, node) {
			let _this = this;
			chooseImage(
				{ count: count },
				({ tempFilePaths, tempFiles }) => {
					// app._log('图片上传2',tempFilePaths,tempFiles)
					let imgList = _this.userInfo[node];
					tempFilePaths.forEach(e => {
						imgList.unshift({ src: e, state: 0 });
					});
					_this.userInfo[node] = imgList;
					//循环上传图片
					tempFilePaths.forEach((url, index) => {
						try {
							_this.fileUpload(
								url,
								(src, state, url = '') => {
									app._log(src, state, url);
									_this.userInfo[node][index].state = state ? 2 : 1;
									if (url != '') {
										_this.userInfo[node][index].url = url;
									}
								},
								err => {
									app._log(err);
								}
							);
						} catch (e) {
							//TODO handle the exception
						}
					});
				},
				err => {
					this.showToast('选择图片失败');
					app._log(err);
				}
			);
		},
		// 单张图片上传
		fileUpload(src, success, fail) {
			this.getSign(
				src,
				sres => {
					//获取签名
					app._log('签名成功', sres);
					this.uploadFile(
						sres,
						(state, url) => {
							// 图片上传
							app._log('图片上传成功', src, state, url);
							success(src, state, url);
						},
						uerr => {
							app._log('图片上传失败', uerr);
							success(src, false);
						}
					);
				},
				serr => {
					app._log('获取签名失败', serr);
					success(src, false); // 获取签名失败
				}
			);
		},
		// 给将要上传的图片签名
		getSign(url, callback, fail) {
			API.ossSign()
				.then(({ code, data, msg }) => {
					if (code == 1) {
						let { accessid, dir, expire, host, policy, signature } = data;
						callback && callback({ src: url, url: host, key: dir + this.returnFileName(url), policy: policy, OSSAccessKeyId: accessid, signature: signature });
					} else {
						// app._log(msg)
						this.showToast(msg);
						fail && fail(url);
					}
				})
				.catch(err => {
					app._log(err);
					this.showToast('图片上传失败，请联系管理员');
					fail && fail(url);
				});
		},
		uploadFile({ src, url, key, policy, OSSAccessKeyId, signature }, success, fail) {
			uni.uploadFile({
				url: url,
				name: 'file',
				filePath: src,
				formData: {
					key: key,
					policy: policy,
					OSSAccessKeyId: OSSAccessKeyId,
					success_action_status: '200', //让服务端返回200,不然，默认会返回204
					signature: signature
				},
				success: res => {
					app._log(res);
					if (res.statusCode == 200) {
						success && success(true, url + '/' + key);
					} else {
						fail && fail(false);
					}
				},
				fail: err => {
					app._log(err);
					fail && fail(false);
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.page {
	background-color: #fff;
	.page_bg {
		position: absolute;
		left: 0;
		top: 0;
		width: 750rpx;
		height: 554rpx;
		z-index: 0;
	}
	.tab_list {
		position: relative;
		padding-top: 232rpx;
		z-index: 1;
		width: 750rpx;
		height: 440rpx;
		display: flex;
		justify-content: space-around;
		.tab_item {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			position: relative;
			&.tab_item_active{
				top: -10rpx;
				.line_height{
					left:115rpx!important;
				}
			}
			.num {
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 50%;
				margin-bottom: 38rpx;
				font-size: 32rpx;
				color: #7b4be6;
				width: 64rpx;
				height: 64rpx;
				background-color: #b799f0;
				position: relative;
				&.active {
					width: 104rpx;
					height: 104rpx;
					border: 16rpx solid #b799f0;
					background-color: #fff;
					color: #8958e6;
					margin-bottom: 18rpx;
				}
				.line_height {
					width: 48rpx;
					height: 3rpx;
					position: absolute;
					// top: 0;
					background-color: #b799f0;
					left: 105rpx;
					&.line_height_left{
						left: 95rpx;
					}
				}
				
			}
			.text {
				text-align: center;
				font-size: 26rpx;
				line-height: 36rpx;
				color: #b799f0;
				&.active {
					color: #fff;
				}
			}
		}
	}
	.no-b-b{
		border-bottom: 0rpx !important;
	}
	.main {
		width: 750rpx;
		// max-height: calc(100vh - 440rpx - constant(safe-area-inset-bottom));
		// max-height: calc(100vh - 440rpx - env(safe-area-inset-bottom));
		padding: 48rpx 0 calc(116rpx - constant(safe-area-inset-bottom));
		padding: 48rpx 0 calc(116rpx - env(safe-area-inset-bottom));
		position: relative;
		z-index: 2;
		background-color: #fff;
		box-shadow: 0rpx 0rpx 40rpx 0rpx rgba(0, 0, 0, 0.02);
		border-radius: 64rpx 64rpx 0rpx 0rpx;
		.comment_box {
			display: flex;
			font-size: 32rpx;
			padding: 0 48rpx 24rpx;
			&:not(.foramt){
				border-bottom: 2rpx solid #ededed;
			}
			&.foramt{ //实名认证上传标准
				border-top: 16rpx solid #f8f8f8;
				padding-top: 40rpx;
				.foramt_text{
					margin-bottom: 32rpx;
					font-size: 28rpx;
					line-height: 40rpx;
					color: #8f8f9a;
				}
				image{
					width: 654rpx;
					margin-bottom: 114rpx;
				}
			}
			.tips{
				padding: 24rpx 0;
				font-size: 26rpx;
				color: #8F8F9A;
			}
			&:not(:first-child) {
				padding-top: 26rpx;
			}
			& > text:not(.foramt) {
				line-height: 44rpx;
				color: #252748;
				padding-right: 64rpx;
			}
			.input {
				padding-bottom: 8rpx;
			}
			.placeholder {
				color: #d1d2db;
			}
			.no_border{
				border: none!important;
			}
			.add_view {
				margin-top: 24rpx;
				background-color: #fff;
				border-radius: 8rpx;
				border: dashed 2rpx #c1c2cb;
				display: flex;
				justify-content: center;
				align-items: center;
				flex-direction: column;
				image {
					width: 40rpx;
					height: 40rpx;
				}
				text {
					font-size: 24rpx;
					line-height: 34rpx;
					color: #c1c2cb;
					margin-top: 8rpx;
				}
			}
			.img_list {
				.img_view {
					position: relative;
					margin-top: 24rpx;
					.img_icon {
						position: absolute;
						width: 44rpx;
						height: 44rpx;
						right: 0;
						top: 0;
						z-index: 5;
					}
					.err {
						position: absolute;
						left: 0;
						top: 0;
						width: 100%;
						height: 100%;
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						z-index: 3;
						background-color: rgba(0, 0, 0, 0.5);
						.state_icon {
							width: 56rpx;
							height: 56rpx;
							margin-bottom: 8rpx;
						}
					}
				}
			}
		}
	}
	.img_list,
	.first_view,
	.center_view,
	.last_view {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		&:after {
			content: '';
			width: auto;
		}
	}
	.first_view {
		.add_view,
		.img_view,
		.img {
			width: 144rpx;
			height: 144rpx;
		}
	}
	// .first_view::after {
	// 	    content: '';
	// 	    flex: auto;    /* 或者flex: 1 */
	// 	}
	.center_view {
		.add_view,
		.img_view,
		.img {
			width: 304rpx;
			height: 176rpx;
		}
	}
	.last_view {
		.add_view,.img_view,
		.img {
			width: 654rpx;
				height: 324rpx;
		}
	}
}
.dom_tree{
	padding: 0rpx 48rpx;
}
.bottom_btn {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 654rpx;
	height: calc(116rpx + constant(safe-area-inset-bottom));
	height: calc(116rpx + env(safe-area-inset-bottom));
	background-color: #fff;
	padding-top: 12rpx;
	padding-bottom:12rpx;
	margin: 0 48rpx;
	display: flex;
	justify-content: space-between;
	z-index: 6;
	view {
		width: 316rpx;
		height: 92rpx;
		border-radius: 16rpx;
		font-size: 32rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		&.active_btn {
			color: #fff;
			background-image: linear-gradient(270deg, #7f4aff 0%, #9254ff 100%);
		}
		&.border_btn {
			color: #7f4aff;
			border: solid 2rpx #7f4aff;
		}
		&.gery_btn {
			color: #d1d2db;
			background-color: #f0f0f6;
		}
	}
	.big_btn {
		width: 654rpx;
	}
}
</style>
